package kr.hkit.powerjava.chapter08.submit;

public class BankAccount {
	private String owner;
	private int accountNumber;
	private int balance;
	
	public BankAccount(String owner, int accountNumber, int balance) {
		this.owner = owner;
		this.accountNumber = accountNumber;
		this.balance = balance;
	}

	public String getOwner() {
		return owner;
	}
	public void setOwner(String owner) {
		this.owner = owner;
	}
	public int getAccountNumber() {
		return accountNumber;
	}
	public void setAccountNumber(int accountNumber) {
		this.accountNumber = accountNumber;
	}
	public int getBalance() {
		return balance;
	}
	public void setBalance(int balance) {
		this.balance = balance;
	}
	public void deposit(int amount) {
		balance += amount;
	}

	public int withdraw(int amount) {
		if (balance < amount || balance ==0) {
			System.out.println("출금 불가. 잔액은: " + balance);
			return -1;
		}else{
			balance -= amount;
			return amount;
		}
	}
	
	public int transfer (int amount, BankAccount otherAccount){
		if (balance < amount || balance ==0) {
			System.out.println("출금 불가. 잔액은: " + balance);
			return -1;
		}else{
			balance -= amount; //김태희 잔고에서 송금위해 인출되는 과정
			otherAccount.setBalance(otherAccount.getBalance()+amount);
			// 조인성 밸런스 잔고 송금 과정
			return amount; 
		} 
	}

	@Override
	public String toString() {
		return "예금주: " + owner + ", 계좌번호: "
				+ accountNumber + ", 잔고: " + balance + "원" ;
	}
}
